<?php

/**
 * PointLogModel 模型
 * Class PointLogModel
 */
class PointLogModel extends BaseModel
{

    public $tableName = "point_log";
    public $errMsg = '';

    public static $descriptionType = [
        1   => '[充值赠送]',
        2   => '[转账支出]',
        3   => '[转账收入]',
        4   => '[成员充值奖励]',
        5   => '[平台释放]',
        6   => '[静态算力增长]',
        7   => '[动态算力增长]'
    ];

    public static $typeArr = [
        1   => '入账',
        2   => '出账'
    ];

    public static $cateArr = [
        1   => '购买构树链赠送',
        2   => '转账支出',
        3   => '转账收入',
        4   => '充值奖励',
        5   => '积分释放',
        6   => '智力算力增长',
        7   => '链接算力增长',
        8   => '购物消耗'
    ];

    //1显示 + ，-1显示 -
    public static $upOrdown = [
        //金券
        1   => [
            1   => 1,
            2   => 0,
            3   => 0,
            4   => 0,
            5   => -1,
            6   => 0,
            7   => 0,
            8   => 0,
            9   => 0
        ],
        //购物
        2   => [
            1   => 0,
            2   => 0,
            3   => 0,
            4   => 0,
            5   => 1,
            6   => 0,
            7   => 0,
            8   => -1,
            9   => 0
        ]
    ];

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'charge_id'     => isset($data['charge_id'])? $data['charge_id']: 0,
                'type'          => $data['type'],
                'cate'          => $data['cate'],
                'user_id'    => $data['user_id'],
                'from_user_id'  => $data['from_user_id'],
                'amount_before' => $data['amount_before'],
                'amount'        => $data['amount'],
                'amount_after'  => $data['amount_after'],
                'f_amount_before' => $data['f_amount_before'],
                'f_amount'        => $data['f_amount'],
                'f_amount_after'  => $data['f_amount_after'],
                'description'   => $data['description'],
                'create_time'   => isset($data['create_time'])? $data['create_time']: time()
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }
}